package com.itheima.myfile;

import java.io.File;

public class Demo7 {
    public static void main(String[] args) {
        File file = new File("D:\\FileTest");
        deleteDir(file);
    }

    private static void deleteDir(File file) {
        //先遍历挨个查找里面文件夹的文件
        File[] files = file.listFiles();
        //对其进行遍历判断
        if (files != null) {
            //如果不等于0就遍历删除
            for (File file1 : files) {
                if (file1.isFile()) {
                    file1.delete();
                } else {
                    deleteDir(file1);
                }
            }
        }
        if (files.length == 0) {
            file.delete();
        }

    }
}
